import { defineComponent, watch, computed, reactive } from "vue";
import { createNamespace } from "../utils";
import FanPicker from "../picker/picker.js";
const __vue_sfc__ = defineComponent({
  name: createNamespace("TimePicker")[0],
  options: { virtualHost: true },
  emits: ["update:show", "update:modelValue", "confirm", "cancel"],
  components: { FanPicker },
  props: {
    modelValue: {
      type: Array,
      default: () => []
    },
    show: {
      type: Boolean,
      default: false
    },
    title: String,
    filter: {
      type: [Function, null],
      default: null
    },
    cancelText: {
      type: String,
      default: "\u53D6\u6D88"
    },
    confirmText: {
      type: String,
      default: "\u786E\u8BA4"
    },
    second: {
      type: Boolean,
      default: false
    }
  },
  setup(props, { emit }) {
    const formatTime = (val, type) => {
      let arr = Array.from({ length: val }, (_, index) => index < 10 ? `0${index}` : index);
      if (props.filter)
        arr = props.filter(type, arr);
      arr = arr.map((item, index) => ({ text: item, id: index < 10 ? `0${index}` : String(index), index }));
      return arr;
    };
    const state = reactive({
      innerShow: props.show,
      value: props.modelValue,
      hours: formatTime(24, "hours"),
      minute: formatTime(60, "minute"),
      second: formatTime(60, "second")
    });
    const list = computed(() => {
      let l = [state.hours, state.minute];
      if (props.second)
        l.push(state.second);
      return l;
    });
    const onConfirm = (val) => emit("confirm", val);
    const onCancel = (val) => emit("cancel");
    watch(props.modelValue, (val) => {
      state.value = [...val];
    }, { deep: true });
    watch(() => state.value, (val) => {
      emit("update:modelValue", val);
    }, { deep: true });
    watch(() => props.show, (val) => state.innerShow = val);
    watch(() => state.innerShow, (val) => emit("update:show", val));
    return { state, list, onConfirm, onCancel };
  }
});
import { renderSlot as _renderSlot, resolveComponent as _resolveComponent, withCtx as _withCtx, createSlots as _createSlots, openBlock as _openBlock, createBlock as _createBlock } from "vue";
function __vue_render__(_ctx, _cache) {
  const _component_FanPicker = _resolveComponent("FanPicker");
  return _openBlock(), _createBlock(_component_FanPicker, {
    modelValue: _ctx.state.value,
    "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => _ctx.state.value = $event),
    show: _ctx.state.innerShow,
    "onUpdate:show": _cache[1] || (_cache[1] = ($event) => _ctx.state.innerShow = $event),
    data: _ctx.list,
    "value-key": "id",
    title: _ctx.title,
    "cancel-text": _ctx.cancelText,
    "confirm-text": _ctx.confirmText,
    onConfirm: _ctx.onConfirm,
    onCancel: _ctx.onCancel
  }, _createSlots({
    _: 2
    /* DYNAMIC */
  }, [
    _ctx.$slots.default ? {
      name: "header",
      fn: _withCtx(() => [
        _renderSlot(_ctx.$slots, "default")
      ]),
      key: "0"
    } : void 0
  ]), 1032, ["modelValue", "show", "data", "title", "cancel-text", "confirm-text", "onConfirm", "onCancel"]);
}
__vue_sfc__.render = __vue_render__;
var stdin_default = __vue_sfc__;
export {
  stdin_default as default
};
